package com.suneee.base.util;

import com.suneee.base.context.OnlineUser;
import com.suneee.base.context.Session;
import com.suneee.component.cache.thread.ThreadLocalCache;
import com.suneee.sso.admin.entity.Administrator;

public class UserThreadLocal {

private static final String SESSION = "session";
    
    public static void setSession(Session session){
        ThreadLocalCache.setObject(SESSION, session);
    }

    public static Session getSession(){
        if(null == ThreadLocalCache.getObject(SESSION)){
            return null;
        }else{
            return (Session)ThreadLocalCache.getObject(SESSION);
        }
    }
    
    public static Administrator getUser(){
        OnlineUser onlineUser = getOnlineUser();
        if(null != onlineUser){
            return onlineUser.getAdmin();
        }
        return null;
    }

    public static OnlineUser getOnlineUser(){
        Session session = getSession();
        if(null == session){
            return null;
        }
        return session.getOnlineUser();
    }
    
    public static void clear(){
        ThreadLocalCache.clear();
    }
}
